package com.iwinding.ladygg.ui.act;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import com.iwinding.ladygg.R;

/**
 * Created by hezhiyong on 2017/3/20.
 */

public class NameActivity extends BaseActivity {

    public static final String NAME = "name";

    private String name;
    private EditText mTvName;
    private ImageView mImgClear;

    @Override
    protected int getLayoutID() {
        return R.layout.icane_activity_name;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        name = getIntent().getStringExtra(NAME);
        initView();
        mBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                name = mTvName.getText().toString();
                Intent data = new Intent();
                data.putExtra(NAME,name);
                setResult(RESULT_OK,data);
                finish();
            }
        });
    }

    void initView() {
        setBackTxtResId(R.string.icane_my_personal_info);
        setTitleResId(R.string.icane_change_name);


        mTvName = (EditText) findViewById(R.id.info_name);
        mImgClear = (ImageView) findViewById(R.id.clear_name);

        mTvName.setText(TextUtils.isEmpty(name) ? "" : name);
        mTvName.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if(hasFocus){
                    mImgClear.setVisibility(View.VISIBLE);
                }else{
                    mImgClear.setVisibility(View.GONE);
                }
            }
        });

        mImgClear.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mTvName.setText("");
            }
        });

    }

}
